/*
*****************************************************************************
* COPYRIGHT AND WARRANTY INFORMATION
* Copyright 2014-2015
* Contributors: Yimin ZHOU, yiminzhou@uestc.edu.cn
*               Minke LUO,  luominke@hotmail.com 
*               Min ZHONG,  201321060446@std.uestc.edu.cn
*               Ce ZHU,     eczhu@uestc.edu.cn
* Institution:  University of Electronic Science and Technology of China
******************************************************************************
*/

#ifndef _RATECONTRAL_H_
#define _RATECONTRAL_H_

#include <stdio.h>
#include <stdlib.h>

typedef struct RateControl
{
	int		RConoff;
	int		IntraPeriod;
	int		TotalFrames;
	int		GlobalImageNumber;
	int		CodedFrameNumber;
	int		ImageType;
	int		ImageQP;
	int		DeltaQP;
	int		GopLeaderDeltaQP;
	int     RcQP;
	int		FrameWidth;
	int		FrameHeight;
	double  ImageBpp;
	double  Belta;
	double  GopBpp;
	int     GopAvgBaseQP;
	int     GopAvgBaseQPCount;
	double  GopAllKeyBpp;
	double  FirstBufferSizeLevel;
	double	IntraFrameBpp;
	double	InterFrameBpp;
	double	TargetBitrate;
	double	TargetBitPerPixel;
	double	TargetBufferLevel;
	double	DeltaBufferLevel;
	double	CurrentBufferSizeBpp;
	double	BufferError;
	double	BufferDifError;
	double	PreBufferError;
	int     GopFlag;
	FILE    *ReportFile;
}RateControl;

void Init_RateControl(RateControl * prc, int rconoff, int totalframes, int intraperiod, int targetbitrate, int framerate, int iniQP, int w, int h, char * filename);
void Updata_RateControl(RateControl * prc, int framebits, int frameqp, int imgtype, int framenumber, int goplength);
int  CalculateGopDeltaQP_RateControl(RateControl * prc, int imgtype, int framenumber, int goplength);
void Destroy_RateControl(RateControl * prc);
void Init_FuzzyController(double ScaFactor);
RateControl * pRC;

#endif